package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Navtop;
import com.ruoyi.system.service.INavtopService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页中部导航模块Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/system/navtop")
public class NavtopController extends BaseController
{
    private String prefix = "system/navtop";

    @Autowired
    private INavtopService navtopService;

    @RequiresPermissions("system:navtop:view")
    @GetMapping()
    public String navtop()
    {
        return prefix + "/navtop";
    }

    /**
     * 查询首页中部导航模块列表
     */
    @RequiresPermissions("system:navtop:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Navtop navtop)
    {
        startPage();
        List<Navtop> list = navtopService.selectNavtopList(navtop);
        return getDataTable(list);
    }

    /**
     * 导出首页中部导航模块列表
     */
    @RequiresPermissions("system:navtop:export")
    @Log(title = "首页中部导航模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Navtop navtop)
    {
        List<Navtop> list = navtopService.selectNavtopList(navtop);
        ExcelUtil<Navtop> util = new ExcelUtil<Navtop>(Navtop.class);
        return util.exportExcel(list, "首页中部导航模块数据");
    }

    /**
     * 新增首页中部导航模块
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页中部导航模块
     */
    @RequiresPermissions("system:navtop:add")
    @Log(title = "首页中部导航模块", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Navtop navtop)
    {
        return toAjax(navtopService.insertNavtop(navtop));
    }

    /**
     * 修改首页中部导航模块
     */
    @RequiresPermissions("system:navtop:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Navtop navtop = navtopService.selectNavtopById(id);
        mmap.put("navtop", navtop);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页中部导航模块
     */
    @RequiresPermissions("system:navtop:edit")
    @Log(title = "首页中部导航模块", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Navtop navtop)
    {
        return toAjax(navtopService.updateNavtop(navtop));
    }

    /**
     * 删除首页中部导航模块
     */
    @RequiresPermissions("system:navtop:remove")
    @Log(title = "首页中部导航模块", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(navtopService.deleteNavtopByIds(ids));
    }
}
